package com.test.daily.leetcode.y2021.m10.day1004;

import java.util.ArrayDeque;

/**
 * lengthOfLongestSubstring
 *
 * @author Tom on 2021/10/4
 */
public class Algo100402_LengthOfLongestSubstring {

    public static void main(String[] args) {
        String s = "ynyo";
        int result= lengthOfLongestSubstring(s);
        System.out.println("result:"+result);
    }

    public static int lengthOfLongestSubstring(String s) {
        char[] str = s.toCharArray();
        ArrayDeque<Character> deque = new ArrayDeque<>();
        int ans = 0;
        for (int i = 0; i < str.length; i++) {
            while(deque.contains(str[i])){
                deque.poll();
            }
            deque.add(str[i]);
            ans = Math.max(ans, deque.size());
        }
        return ans;
    }
}
